package com.springboot.hotel.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class EmailConfig {
    @Bean
    public JavaMailSenderImpl javaMailSender() {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
//        这里额外的设置了一些属性
//        原因是我在yml文件中配置之后，运行测试类时，还是会使用localhost:25发送邮件，所以我在这里再次设置了一下，防止覆盖
        javaMailSender.setHost("smtp.qq.com");
        javaMailSender.setPort(465);
        javaMailSender.setUsername("1264161650@qq.com");
        javaMailSender.setPassword("thaygewezzhzhfhf");
        javaMailSender.getJavaMailProperties().setProperty("mail.smtp.ssl.enable", "true");
        javaMailSender.getJavaMailProperties().setProperty("mail.smtp.auth", "true");
        javaMailSender.getJavaMailProperties().setProperty("mail.smtp.required", "true");
        return javaMailSender;
    }
}
